<meta charset="UTF-8">
<title>Insert title here</title>
<div id=div9>
	<h3 style="text-align: center;">个人成绩录入</h3>
	<div class="container" style="padding: 10px;">
		<form action="abc" method="post" class="form-horizontal">
			<div class="form-group">
				<label class="col-md-1 control-label">选择班级:</label>
				<div class="col-md-2">
					<input class="form-control" id="aclass" type="text"
						disabled="disabled" />
				</div>

				<label class="col-md-1 control-label">选择学生:</label>
				<div class="col-md-2">
					<input class="form-control" id="stu" type="text"
						disabled="disabled" />
				</div> 
				<div>
				   <button type="button" class="btn btn-primary glyphicon glyphicon-search" id="cx">查询</button>
				</div>
			</div>
			<div class="form-group">
			
			</div>
		</form>

</div>
	<!-- 表格div3 -->
	<div id="div3" class="container" style="flex-grow: 1; display: none;">
		<table id="bjcj">
			<thead>
				<tr>


				</tr>
			</thead>
		</table>
	</div>

	<div id="div2" class="container" style="flex-grow: 1; display: none;">
		<table id="bjcj1">

		</table>
	</div>
</div>
</body>
<script type="text/javascript">
$(function(){
	$('#aclass').combobox({
	     	editable:false,
			url:'banji/list',
			valueField:'id',
			textField:'name',
			onchange:function(id){
				$('#stu').combobox('destroy');
				var bjId=id;
				$('#div').show();
				$('#stu').combobox({
					url:'grade/getStu?bjId='+bjId,
					valueField:'id',
					textField:'name',
				})
				$('#stu').combobox('enable');
				}

	
			});//combobox
	var grid = $('#bjcj');
	$('#cx').bind('click',function(){
		var stuId=$('#stu').combobox('getValue');
		var bjId=$('#aclass').combobox('getValue');
		if(bjId==0||stuId==0){
				$('#div3').hide();
				return;
			}else{
				$('#div3').show();
				
		}
		grid.datagrid({
			url: 'grade/getPersonGrade?stuId='+stuId,
			search: false,
			pagination: false,
			buttons:[],
			columns:[
				[
				{title:'aa',field:'aa',checkbox:true},
		        {field:'student.tbClass.name',title:'班级'},
		        {field:'student.stuNo',title:'学号'},
		       /*  {field:'student.name',title:'姓名'}, */
		        {field:'course.name',title:'课程'},
		        {field:'grade',title:'成绩',formatter: function formatOper(val, row, index) {   
		    	 	if(row.grade==null){

		    	           row.grade=0;
		    			 	}
            return '<input type="number" min="0" max="150" class="form-control" onchange="xg('+row.id+',value)" id="input" value="'+row.grade+'"/>';
		    	        }}
		  		  ]
				],
		});

	});
})
	
	function formatOper(val, row, index) {   
	 	if(row.grade==null){

	       row.grade=0;
		 	}
		 		 return '<input id="input" value="'+row.grade+'"/>';
	    }

	$("input[id='input']").numberbox({
	    min:0,
	    precision:0
	});
	function cjChange(bjId,stuId){
		$('#bjcj').datagrid($.extend({},$.crudgrid.defaults,{
			url:'grade/getPersonGrade?stuId='+stuId,
			onLoadSuccess:function(data){
		            $("input[id='input']").numberbox({
		            	onChange:function(grade,oldgrade){
			            	var grid=$('#bjcj').datagrid('getSelected');
							xg(grid.id,grade);
			            }
			        });  
		   	}
		}))
	};
	function xg(id,grade){
		if(!(/^[0-9]\d*$/.test(grade))){
			$.messager.alert('提示','请输入正整数','info');
			return;
		};
	$.post('grade/cjChange',{id:id,grade:grade},function(data){});
	}
			
			

</script>